package com.hqj.util;

import com.cloopen.rest.sdk.CCPRestSmsSDK;

import java.util.HashMap;

public class SendMsgUtil {

    /**
     * 发送短信验证码
     * @param to  接收号码
     * @param templateId 短信模板id(测试模板为沙盒0)
     * @param datas 数组 包含发送的内容及有效时间
     * @return
     */
    public static boolean sendSms(String to,String templateId,String datas[]){
        boolean flat = false;
        try {
            //声明短信发送类
            CCPRestSmsSDK restApi = new CCPRestSmsSDK();

            //设置参数
            restApi.init("app.cloopen.com","8883");
            restApi.setAccount("8a48b5515249574b015252af55751033","ed8667cafc7a46649781225d8a36b823");
            restApi.setAppId("8a48b5515249574b015252c3cbf31091");

            //执行发送
            HashMap<String,Object> resulft = restApi.sendTemplateSMS(to,templateId,datas);
            System.out.println("短信发送结果:"+resulft.toString());
            if("000000".equals(resulft.get("statusCode"))){
                flat = true;
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return flat;
    }

    public static void main(String[] args) {
        String code = "1234";
        String datas[] = {code,"5"};

        boolean flat = sendSms("18577867151","1",datas);
        System.out.println("短信发送"+(flat?"成功":"失败"));
    }
}
